<template>
<!-- 学生端签到页面-->
  <div class="com-page stusigninpage">
    <el-container>
      <el-header style="width: 60%;margin: 80px auto">
        <el-steps :active="active" align-center finish-status="success">
          <el-step title="检查个人基础信息" description="检查基础信息无误后请点击下一步"></el-step>
          <el-step title="个人信息完善" description="完善个人信息后请点击确定"></el-step>
          <el-step title="签到" description="检查个人信息无误后点击签到以完成线上签到"></el-step>
        </el-steps>
        <el-button style="margin-top: 12px;" @click="last" v-show="active>0">上一步</el-button>
        <el-button style="margin-top: 12px;" @click="next" v-show="active<2">下一步</el-button>
      </el-header>
      <el-main class>
        <router-view @childFn="paraentFn"></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<script>

export default {
  name: "StuSignIn",
  created() {
    this.active=0
  },
  mounted() {
    this.active=0
  },
  data() {
    return {
      active: 0,
      id: JSON.parse(localStorage.getItem("user")).id,
    };
  },
  methods: {
    next() {
      this.active++
      if (this.active == 1) {
        this.$router.push("/stuSignIn/informationComplete")
      }
      if (this.active == 2) {
        // 根据id获取当前更新后的学生数据，并存储于stuInfo中
        this.request.get("/student/" + this.id).then(res => {
          if (res.code == 20041) {
            localStorage.setItem("stuInfo", JSON.stringify(res.data))
          } else if (res.code == 20040) {
            this.$message.error(res.msg)
          } else {
            this.$message.error(res.msg)
          }
        }).finally(() => {
          this.$router.push("/stuSignIn/signIn")
        })
      }
    },
    last() {
      this.active--
      if(this.active==0) {
        this.$router.push("/stuSignIn/basicInfo")
      }
      if (this.active == 1) {
        this.$router.push("/stuSignIn/informationComplete")
        localStorage.removeItem("stuInfo")
      }
      if (this.active == 2) {
          this.$router.push("/stuSignIn/signIn")
      }
    },
    paraentFn(message) {
      this.active=message
    }

  }

}
</script>

<style scoped>
.stusigninpage {
  background-color: beige;
}
</style>